home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / computerjanitor / plugins / fstab_plugin.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  5.0 KB  |  121 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import fstab
  5. import computerjanitor
  6. import computerjanitorapp
  7. _ = computerjanitorapp.setup_gettext()
  8.  
  9. class FstabCruftBase(computerjanitor.Cruft):
  10.     '''Base class for cruft in the fstab file.'''
  11.     
  12.     def __init__(self, fstab_line):
  13.         self.fstab_line = fstab_line
  14.  
  15.  
  16.  
  17. class RelatimeCruft(FstabCruftBase):
  18.     """Cruft consisting of a missing 'relatime' option for a filesystem."""
  19.     
  20.     def get_prefix(self):
  21.         return 'relatime'
  22.  
  23.     
  24.     def get_prefix_description(self):
  25.         return 'fstab mount option relatime missing'
  26.  
  27.     
  28.     def get_shortname(self):
  29.         return self.fstab_line.directory
  30.  
  31.     
  32.     def get_description(self):
  33.         return _("The 'relatime' mount option is missing for filesystem mounted at %s") % self.fstab_line.directory
  34.  
  35.     
  36.     def cleanup(self):
  37.         if 'relatime' not in self.fstab_line.options:
  38.             self.fstab_line.options += [
  39.                 'relatime']
  40.         
  41.  
  42.  
  43.  
  44. class Scd0Cruft(FstabCruftBase):
  45.     '''Rewrite iso9660 fs devices as/dev/cdrom in fstab.'''
  46.     
  47.     def get_prefix(self):
  48.         return 'scd0'
  49.  
  50.     
  51.     def get_prefix_description(self):
  52.         return '/dev/scd0 should be /dev/cdrom'
  53.  
  54.     
  55.     def get_shortname(self):
  56.         return '/dev/scd0'
  57.  
  58.     
  59.     def get_description(self):
  60.         return _("The '/dev/scd0' device should be '/dev/cdrom' in fstab.")
  61.  
  62.     
  63.     def cleanup(self):
  64.         if self.fstab_line.device == '/dev/scd0':
  65.             self.fstab_line.device = '/dev/cdrom'
  66.         
  67.  
  68.  
  69.  
  70. class FstabPlugin(computerjanitor.Plugin):
  71.     """Plugin to modify /etc/fstab.
  72.     
  73.     This plugin will add the relatime mount option to /etc/fstab
  74.     to those ext2 and ext3 filesystems that are missing it.
  75.     
  76.     In the future, it may do other things. We'll see. The goal is
  77.     to provide a way to add tweaks to /etc/fstab upon upgraded that
  78.     would be there if the system was installed from scratch.
  79.     
  80.     """
  81.     allowed_fstypes = [
  82.         'ext2',
  83.         'ext3']
  84.     
  85.     def __init__(self):
  86.         self.fstab_filename = '/etc/fstab'
  87.         self.fstab = None
  88.  
  89.     
  90.     def is_relatime_cruft(self, line):
  91.         if line.fstype in self.allowed_fstypes and 'relatime' not in line.options:
  92.             pass
  93.         return 'noatime' not in line.options
  94.  
  95.     
  96.     def is_scd0_cruft(self, line):
  97.         return False
  98.  
  99.     
  100.     def get_cruft(self):
  101.         tests = [
  102.             (self.is_relatime_cruft, RelatimeCruft),
  103.             (self.is_scd0_cruft, Scd0Cruft)]
  104.         self.fstab = fstab.Fstab()
  105.         self.fstab.read(self.fstab_filename)
  106.         cruft = []
  107.         for line in self.fstab.lines:
  108.             for test, klass in tests:
  109.                 if test(line):
  110.                     cruft.append(klass(line))
  111.                     continue
  112.             
  113.         
  114.         return cruft
  115.  
  116.     
  117.     def post_cleanup(self):
  118.         self.fstab.write(self.fstab_filename)
  119.  
  120.  
  121.